-
Notifications
You must be signed in to change notification settings - Fork 11.8k
[12.x] Table prefix not applied when cloning connections #58288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Hafez Divandari <[email protected]>
|
@hafezdivandari Thanks for taking a look at this! Naturally, you're most familiar with the changes in #54487 😅 Those seemed like the only method calls necessary when cloning, but let me know if I'm forgetting anything |
|
The framework/src/Illuminate/Database/Connection.php Lines 250 to 253 in fa48122
framework/src/Illuminate/Database/Connection.php Lines 260 to 263 in fa48122
In contrast,
Therefore, I think calling For reference, the main issue also exists in the 11.x branch. When cloning a connection, the grammar instances continue to reference the original connection rather than the cloned one. As a result, my PR targeting 12.x did not introduce a new bug, but rather exposed an existing one! |
|
@hafezdivandari Thanks for the insight, I went ahead and removed That's an interesting point you raised about your PR exposing an existing bug. The issue was reported as a regression, but as you noted, it also existed in a different capacity in 11.x. Users likely didn't notice because the unintended side effect (shared grammar affecting both connections) happened to make their cloned connection work correctly, even though it incorrectly modified the original connection. I've updated the PR description to better reflect what's going on here. |
Fixes #56902
Problem
When cloning a database connection and setting a different table prefix, the prefix is not applied correctly.
Root Cause
c78fa3d refactored how grammars access table prefixes. Previously, grammars stored their own
$tablePrefixproperty. Now they dynamically retrieve it from their connection reference.Laravel 11 behavior (before c78fa3d):
When cloning, the grammar object was shallow-copied. Calling
setTablePrefix()on the clone updated the shared grammar, affecting both connections.Laravel 12 behavior (after c78fa3d):
When cloning, the grammar's
$connectionreference still points to the original connection. CallingsetTablePrefix()on the clone only updates the clone's prefix, but the grammar still reads from the original connection, ignoring the new prefix.Solution
Added
__clone()to theConnectionclass to re-initialize grammars with the cloned connection.